#include "gui/layers/CarLayer.h"
#include "gui/objects/GUIRouteCar.h"
#include "util/events/CarMoveEvent.h"
#include "util/events/EventListener.h"

namespace gui {

class CarMoveEventListener : public EventListener {
public:
	CarMoveEventListener(CarLayer* carLayer): EventListener(CarMove_Event) { this->carLayer = carLayer; }
	~CarMoveEventListener() {}
	void execute(Event* event) {
		CarMoveEvent* carMoveEvent = (CarMoveEvent*)event;
		this->carLayer->update(carMoveEvent->getCar(), carMoveEvent->getNextPointToNavigate());
	}
private:
	CarLayer* carLayer;
};

CarLayer::CarLayer(SurfaceFactory* surfaceFactory, CarController* carController): DynamicLayer(surfaceFactory), drawer(surfaceFactory) {
	carController->addEventListener(new CarMoveEventListener(this));
	GUIRouteCar guiRouteCar(&drawer, carController->getCar(), carController->getNextPointToNavigate());
	this->updateSurface(guiRouteCar);
}

CarLayer::~CarLayer() {

}

void CarLayer::update(map::Car* car, MapPoint nextPointToNavigate) {
	GUIRouteCar guiRouteCar(&drawer, car, nextPointToNavigate);
	this->updateSurface(guiRouteCar);
}

}
